home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / a_threshold.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-20  |  2.5 KB  |  104 lines

  1. ;    VirtualDub - Video processing and capture application
  2. ;    Copyright (C) 1998-2001 Avery Lee
  3. ;
  4. ;    This program is free software; you can redistribute it and/or modify
  5. ;    it under the terms of the GNU General Public License as published by
  6. ;    the Free Software Foundation; either version 2 of the License, or
  7. ;    (at your option) any later version.
  8. ;
  9. ;    This program is distributed in the hope that it will be useful,
  10. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;    GNU General Public License for more details.
  13. ;
  14. ;    You should have received a copy of the GNU General Public License
  15. ;    along with this program; if not, write to the Free Software
  16. ;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     .386
  19.     .model    flat
  20.     .code
  21.  
  22.     public _asm_threshold_run
  23.  
  24. ;asm_threshold_run(
  25. ;    [esp+ 4] void *dst,
  26. ;    [esp+ 8] ulong width,
  27. ;    [esp+12] ulong height,
  28. ;    [esp+16] ulong stride,
  29. ;    [esp+20] ulong threshold);
  30. ;
  31. ;    This code is based off of the grayscale code.  See a_grayscale.asm for
  32. ;    further info.
  33.  
  34. _asm_threshold_run:
  35.     push    ebp
  36.     push    edi
  37.     push    esi
  38.     push    edx
  39.     push    ecx
  40.     push    ebx
  41.     push    eax
  42.  
  43.     mov    esi,[esp+ 4+28]
  44.     mov    ebp,[esp+12+28]
  45.  
  46.     mov    eax,[esp+20+28]
  47.     mov    ebx,80000000h
  48.     shl    eax,8
  49.     sub    ebx,eax
  50.     push    ebx
  51.  
  52.  
  53. threshold@rowloop:
  54.     push    ebp
  55.     mov    ebp,[esp+ 8+36]
  56.  
  57.     push    esi
  58. threshold@colloop:
  59.     mov     eax,[esi]        ;1u EAX=?.R.G.B
  60.         xor     ebx,ebx            ;1v EBX=0
  61.         mov     edx,eax            ;2u EDX=?.R.G.B
  62.         and     eax,00ff00ffh        ;2v EAX=[R][B]
  63.         mov     bl,dh            ;3u EBX=[][G]
  64.         mov     edi,eax            ;3v EDI=[R][B]
  65.         xor     ecx,ecx            ;4u ECX=0
  66.         lea     edx,[eax+8*eax]        ;4v EDX=[R*9][B*9]
  67.         lea     ecx,[ebx+2*ebx]        ;5u ECX=[G*3]
  68.         lea     ebx,[ebx+8*ebx]        ;5v EBX=[G*9]
  69.         shl     ecx,6            ;6u ECX=[G*192]
  70.         lea     eax,[edx+2*edx]        ;6v EAX=[R*27][B*27]
  71.         lea     edi,[edi+2*edx]        ;7u EDI=[R*19][B*19]
  72.         sub     ecx,ebx            ;7v ECX=[183*G]
  73.         shr     eax,15            ;8u EAX=[54*R]
  74.         add     ecx,edi            ;8v ECX=[183*G+19*B]
  75.         add     eax,ecx            ;9u EAX=54*R+183*G+19*B
  76.     add    esi,4            ;9v
  77.     and    eax,0000ffffh        ;10u
  78.     add    eax,[esp+8]        ;11u
  79.     sar    eax,31            ;12u
  80.     dec    ebp            ;12v
  81.     mov    [esi-4],eax        ;13u
  82.     jne    threshold@colloop    ;13v
  83.  
  84.     pop    esi
  85.  
  86.     pop    ebp
  87.     add    esi,[esp+16+32]
  88.  
  89.     dec    ebp
  90.     jne    threshold@rowloop
  91.  
  92.     pop    eax            ;remove thresholding temp
  93.  
  94.     pop    eax
  95.     pop    ebx
  96.     pop    ecx
  97.     pop    edx
  98.     pop    esi
  99.     pop    edi
  100.     pop    ebp
  101.     ret
  102.  
  103.     end
  104.